package com.hxci.zhangcong.controller;

import com.hxci.zhangcong.pojo.Course;
import com.hxci.zhangcong.servcie.CorseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("course")
public class CourseController {
    @Autowired
    CorseService service;

    @RequestMapping("view")
    public String view(){
        return "zhangcong/course";
    }

    @RequestMapping("add")
    public String add(){
        return "zhangcong/add";
    }
    //保存
    @ResponseBody
    @RequestMapping("save")
    public Integer save(Course course){
        System.out.println(course);
        Integer flag= service.save(course);
        return flag;
    }
    @ResponseBody
    @RequestMapping("query")
    public List<Course> query(Course  course){
        System.out.println("==========");
        List<Course>  list =  service.query(course);
        return list;
    }
    @ResponseBody
    @RequestMapping("del")
    public Integer del(String id){
        System.out.println("==========");
        Integer flag = service.del(id);
        return flag;
    }
    @RequestMapping("edit")
    public String edit(String id, Model model){
        Course course = service.queryBySno(id);
        model.addAttribute("course",course);
        return "zhangcong/edit";
    }

}
